package Sunjuk;

import java.util.Scanner;

public class EX01_SungJukService implements EX01_ISungJukService{
	private EX01_SungJukDAO mdao = new EX01_SungJukDAO();
	
	@Override
public void createSungJuk() {
		Scanner sc = new Scanner(System.in);
		EX01_SungJukVO s = new EX01_SungJukVO();
		EX01_SungJukService ss = new EX01_SungJukService();
		
		System.out.println("학생 이름");
			s.setName(sc.next());
		while(true){
		System.out.println("국어 점수를 적어");
			s.setKor(sc.nextInt());
			if(s.getKor()>100){System.out.println("범위에서 벗어낫네요");}
			else{break;}
		}
		while(true){
		System.out.println("영어 점수를 적어");
			s.setEng(sc.nextInt());
			if(s.getKor()>100){System.out.println("범위에서 벗어낫네요");}
			else{break;}
		}
		while(true){
		System.out.println("수학 점수를 적어");
			s.setMat(sc.nextInt());
			if(s.getKor()>100){System.out.println("범위에서 벗어낫네요");}
			else{break;}
		}
		if(mdao.insertSungJuk(s, ss))
			System.out.println("성공");
		else
			System.out.println("실패");
}

	@Override
	public int tot(EX01_SungJukVO t) {
		t.setTot(t.getEng() + t.getKor() + t.getMat());
		return t.getTot();
		
	}

	@Override
	public float avg(EX01_SungJukVO t) {
		t.setAvg((float)t.getTot()/(float)3);
		return t.getAvg();
	}

	@Override
	public String grd(EX01_SungJukVO t) {
		
		switch ((int)t.getAvg()/10) {
		case 10:
		case 9:	t.setGrd("수"); break;
		case 8:	t.setGrd("우"); break;
		case 7:	t.setGrd("미"); break;
		case 6:	t.setGrd("양"); break;
		default: t.setGrd("가");
		};
		return t.getGrd();
		
	}
	
	@Override
	public void readSungJuk() {
		for( EX01_SungJukVO s : mdao.selectSungJuk()){
			System.out.print( s.getSjno());
			System.out.print( "/");
			System.out.print( s.getName());
			System.out.print( "/");
			System.out.print( s.getKor());
			System.out.print( "/");
			System.out.print( s.getEng());
			System.out.print( "/");
			System.out.print( s.getMat());
			System.out.print( "/");
			System.out.print( s.getTot());
			System.out.print( "/");
			System.out.print( s.getAvg());
			System.out.print( "/");
			System.out.println( s.getGrd());
		}
	}
}
